%%
%2.2.6
syms x
y = x*sin(x^2-x-1);
fplot(y,[-2,0]);
[x,f] = fminbnd('x*sin(x^2-x-1)',-2,0);
%%
a = inline('x*sin(x^2-x-1)','x');
[b,c] = fminsearch(a,-1.2)
%%
%得到最大值，在最前面添加一个负号
%a2 = inline('-x*sin(x^2-x-1)','x');
syms x
y2 = -x*sin(x^2-x-1)
fplot(y2,[-2,0]);
[x,f] = fminbnd('-x*sin(x^2-x-1)',-2,-1);
a2 = inline('-x*sin(x^2-x-1)','x');
[b2,c2] = fminsearch(a2,0);
%%
%讨论一下最值
x = -2:0.01:0;
y = x.*sin(x.^2-x-1);
[m k] = min(y)
%%
%练习2.2
%1
syms n x m
f1 = nthroot(n^3+3^n,n);
limit(f1,inf);
f2 = nthroot(n+2,2)-2*nthroot(n+1,2)+n^0.5;
limit(f2,inf);
f3 = x*cot(2*x);
limit(f3,0);
f4 = cos(m/x)^x;
limit(f4,x,inf);
f5 = (1/x-1/(exp(x)-1));
limit(f5,x,1);
f6 = nthroot(x^2+x,2)-x;
limit(f6,x,inf);
%%
%3
syms x
fplot('x^2*sin(x^2-x-2)',[-2,2]);
y = x^2*sin(x^2-x-2);
yy = diff(y,x,2);
y1y = simplify(yy);
[m,n] = fminbnd('x^2*sin(x^2-x-2)',-2,2);




